package com.qbm.association.service.impl;

import com.qbm.association.entity.Activity;
import com.qbm.association.mapper.ActivityMapper;
import com.qbm.association.service.ActivityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Aron
 * @since 2021-12-12
 */
@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements ActivityService {
    @Autowired
    ActivityMapper activityMapper;
    @Override
    public void add(Map<String, Object> para) {
        Activity activity = new Activity();
//        //转换时间格式
//        Date time= TimeUtil.timeTrans((String)para.get("start_time"));
        //获得时间戳
        long id = System.currentTimeMillis();
//        //生成提交时间
//        Date Submission_time= DateUtil.getDate();

        //获得申请人ID
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        assert attributes != null;
        HttpServletRequest request = attributes.getRequest();
        int originator = Integer.parseInt((String) request.getAttribute("userName"));


        activity.setAddress((String) para.get("address"));
        activity.setAdministrator((int) para.get("administrator"));
        activity.setIntro((String) para.get("describe"));
        activity.setDetails((String) para.get("details"));
        activity.setPhoto((String) para.get("photo"));
        activity.setId((long) id);
        activity.setMaxPerson((int) para.get("max_person"));
        activity.setName((String) para.get("name"));
        activity.setObject((String) para.get("object"));
        activity.setOriginator(originator);
        System.out.println(para.get("start_time"));
        activity.setStartTime((String) para.get("start_time"));
        activity.setSubmissionTime(Calendar.getInstance().getTime());
        activity.setWechat((String) para.get("wechat"));
        activity.setState(0);
        activity.setNumber(0);
        activity.setClubId((int) para.get("club"));
        activityMapper.insert(activity);
    }
}
